home *** CD-ROM | disk | FTP | other *** search
- Path: news.ov.com!news
- From: glenn@ov.com (Fletcher.Glenn@ov.com)
- Newsgroups: comp.lang.c
- Subject: Re: Help - pointer notation please...
- Date: 26 Feb 1996 17:18:28 GMT
- Organization: OpenVision
- Message-ID: <4gsq14$3uc@spanky.pls.ov.com>
- References: <4gjelv$2ek@news.mistral.co.uk>
- Reply-To: glenn@ov.com
- NNTP-Posting-Host: foghorn.pls.ov.com
-
- In article 2ek@news.mistral.co.uk, mikebarnard@mistral.co.uk (Mike Barnard) writes:
- >Hi.
- >
- >I've read my C book. I've gotten th C FAQ. I've read the file
- >"ptrtutor.txt" a tutorial on pointers. But I havn't seen explained the
- >following. Can you help?
- >
- >Sometimes when prototyping a function the function name is pre-fixed
- >by an asterisk. Why? What does it mean?
- >
- >Putting an asterisk before a variable name declares it as a pointer
- >variable. Putting one before the variable in use means you want to
- >access the data pointed to. Why is there sometimes an asterisk AFTER a
- >variable?
- >
- >All hint's will be of GREAT use. Thanks.
- >
- >---
- >Mic.
- >From very windy and now snowy Worthing; England.
- >mikebarnard@mistral.co.uk
- >
- >(I just lost 4 fence panels to the wind here! The cost of
- >replacing them could have bought me a new windows compiler!)
- >
-
- The use of '*' is context dependent. In variable declarations it always
- means pointer (unless it is used in an initializer). In statements it can
- either mean "dereference pointer" or "multiply" depending on how it is used.
-
- Consider:
-
- int ad = 3 * 4, *a, bd, *b, c;
-
- int main()
- {
- b = &bd;
- a = &ad;
- *b = 10;
- c = *a * (*b);
- return(c);
- }
-
- Can you see why c == 120 is true?
-
- Fletcher.Glenn@ov.com
-
-